package eco2automotive.data;
import java.io.*;
import eco2automotive.Log.LogInformation;
import java.util.HashMap;
 /**  
  * This object serializable contains a HashMap to access and storage the
  * Paramaters objects @see eco2automotive.data.Parameter
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  *
  */ 
public class HashParameters implements Serializable{
     HashMap table;
     LogInformation l;      
   /**
    * Default constructor, create a new HashMap 
    */
   public HashParameters(){table = new HashMap();}   
   /** 
    * Constructor
     * @param h - HashMap to assign
    */ 
   public HashParameters(HashMap h){table = h;}   
   /**
    * This method return the object HasMap 
    * @return table - the HasMap
    */
   public HashMap getHash(){return this.table;} 
         
    /** 
     * Insert a new Object type Parameter
     * @param p - Parameter to add
    */
   public void insertParameter(Parameter  p){
        Parameter var;
	String key = new String();
        key=String.valueOf(p.getOperationMode());
        key=key.concat(p.getPidKey());           
			if (!(table.containsKey(key))){
			Object valor = table.put(key,p);     		
			}
			else			
                        {                            
                           var=(Parameter)this.table.get(key);                         
                            //Si existe el Parametro inserto un nuevo PID al parametro.
                            p.addPID(var.getPID(0));
                            //quito el viejo pongo el nuevo
                         this.deleteObject(key) ;
                         Object valor = table.put(key,p);                             
                           //Object val= table.get(key);
                               System.out.println("HASH_Insert_KeyDuplicated "+key);                          
			}
	}

   /** 
    * Returns a object Paramter by code
     * @param code - Code to find in the HashMap
    *  @return object Parameter or null if not exists 
    */
   public Object getObject(String code){
	 Object ob = table.get(code);
	 if (ob==null)
	 	{                 
                return null;
	 	}	
	 return ob;
	}   
    /** 
     * Delete a Parameter by code from the HashMap
     * @param code - The code to delete
    */
   public void deleteObject(String code){
	if (!(table.containsKey(code))){						
			}
			else	
			{	 
				Object value = table.remove(code);			
			}
		}    
   
}
